<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2024/8/26
  Time: 20:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>addAuth</title>
    <link href="../../../static/layui/css/layui.css" rel="stylesheet">
</head>
<body>
    <script src="../../../static/layui/layui.js" type="text/javascript" charset="UTF-8"></script>
    <script src="../../../static/jquery-2.1.4.js" type="text/javascript" charset="UTF-8"></script>
    <script src="../../../static/mylayer.js" type="text/javascript" charset="UTF-8"></script>
    <script src="../../../static/kindeditor/kindeditor.js" type="text/javascript" charset="utf-8"></script>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">权限名</label>
            <div class="layui-input-block">
                <input type="text" name="name" autocomplete="off" placeholder="请输入权限名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限路径</label>
            <div class="layui-input-block">
                <input type="text" name="path" autocomplete="off" placeholder="请输入路径" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">权限所属</label>
            <div class="layui-input-block">
                <select id="role" name="role">
                    <option>请选择所属</option>
                    <option value="1">管理员</option>
                    <option value="2">医生</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="submitDemo">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>
        var kindEditorParams = {
            afterBlur: function () {
                this.sync();
            }
        };
        var editor = KindEditor.create('#contentId',kindEditorParams);

        layui.use(['form'], function () {
            var form = layui.form;

            //监听提交
            form.on('submit(submitDemo)', function(data){
                // layer.alert(JSON.stringify(data.field), {
                //     title: '最终的提交信息'
                // })
                console.log(data.field);
                $.post(
                    '/auth?method=add',
                    data.field,
                    function (result) {
                        console.log(result);
                        if(result.code == 0) {
                            mylayer.okMsg(result.msg);
                            setInterval(function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload();
                            }, 2000);
                        }
                    },
                    'json'
                )
                return false;
            });

        })

    </script>
</body>
</html>
